package models

import (
	"gorm.io/gorm"
	"order_srv/basic/config"
	"time"
)

// DispatchAudit 派单策略与变更审计
type DispatchAudit struct {
	Id         uint64    `gorm:"column:id;type:bigint unsigned;primaryKey;autoIncrement;comment:主键" json:"id"`
	CityId     uint32    `gorm:"column:city_id;type:int unsigned;index;comment:城市ID" json:"city_id"`
	TargetType string    `gorm:"column:target_type;type:varchar(32);comment:对象类型_config/strategy" json:"target_type"`
	TargetKey  string    `gorm:"column:target_key;type:varchar(64);comment:对象键或版本号" json:"target_key"`
	Operator   string    `gorm:"column:operator;type:varchar(64);comment:操作人" json:"operator"`
	ChangeLog  string    `gorm:"column:change_log;type:text;comment:变更详情" json:"change_log"`
	CreatedAt  time.Time `gorm:"column:created_at;type:datetime;not null;default:CURRENT_TIMESTAMP" json:"created_at"`
}

// TableName 表名
func (d *DispatchAudit) TableName() string { return "dispatch_audit" }

// Create 创建
func (d *DispatchAudit) Create(tx *gorm.DB) error {
	if tx != nil {
		return tx.Create(d).Error
	}
	return config.DB.Create(d).Error
}
